package o;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import androidx.annotation.Nullable;
import java.util.concurrent.locks.Lock;

final class wt {
    private static final uc ˎ = new ug() {
        public void ˏ(Bitmap bitmap) {
        }
    };

    @Nullable
    static tx<Bitmap> ˋ(uc ucVar, Drawable drawable, int i, int i2) {
        Bitmap bitmap;
        Object obj;
        Drawable current = drawable.getCurrent();
        if (current instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) current).getBitmap();
            obj = null;
        } else if (current instanceof Animatable) {
            obj = null;
            bitmap = null;
        } else {
            bitmap = ˊ(ucVar, current, i, i2);
            obj = 1;
        }
        if (obj == null) {
            ucVar = ˎ;
        }
        return wh.ˊ(bitmap, ucVar);
    }

    @Nullable
    private static Bitmap ˊ(uc ucVar, Drawable drawable, int i, int i2) {
        Bitmap bitmap = null;
        if (i != Integer.MIN_VALUE || drawable.getIntrinsicWidth() > 0) {
            if (i2 != Integer.MIN_VALUE || drawable.getIntrinsicHeight() > 0) {
                if (drawable.getIntrinsicWidth() > 0) {
                    i = drawable.getIntrinsicWidth();
                }
                if (drawable.getIntrinsicHeight() > 0) {
                    i2 = drawable.getIntrinsicHeight();
                }
                Lock ˊ = xb.ˊ();
                ˊ.lock();
                bitmap = ucVar.ˊ(i, i2, Config.ARGB_8888);
                try {
                    Canvas canvas = new Canvas(bitmap);
                    drawable.setBounds(0, 0, i, i2);
                    drawable.draw(canvas);
                    canvas.setBitmap(null);
                } finally {
                    ˊ.unlock();
                }
            } else if (Log.isLoggable("DrawableToBitmap", 5)) {
                Log.w("DrawableToBitmap", "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the Drawable has no intrinsic height");
            }
        } else if (Log.isLoggable("DrawableToBitmap", 5)) {
            Log.w("DrawableToBitmap", "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the Drawable has no intrinsic width");
        }
        return bitmap;
    }
}
